#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<unordered_map>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
void insert_sort()
{
	for (int i = 2; i <= n; i++)
	{
		int tmp = a[i];
		int j;
		for (j = i-1; j >=1; j--)
		{
			if (a[j] > tmp)
			{
				a[j + 1] = a[j];
			}
			else
			{
				break;
			}

		}
		a[j+1] = tmp;
	}
}
void selection_sort()
{
	for (int i = 1; i < n; i++)
	{
		int tmp = i;
		for (int j = i + 1; j <=n; j++)
		{
			if (a[j] < a[tmp])
			{
				tmp = j;
			}
		}
		swap(a[i], a[tmp]);
	}
}
void down(int parent,int len)
{
	int child = parent * 2;
	while (child <= len)
	{
		if (child + 1 <= len && a[child] < a[child + 1])child++;
		if (a[child] < a[parent])return;
		swap(a[child], a[parent]);
		parent = child;
		child = parent * 2;
	}
	
}
void heap_sort()
{
	for (int i = n / 2; i >= 1; i--)
	{
		down(i, n);
	}
	for (int i = n; i > 1; i--)
	{
		swap(a[1], a[i]);
		down(1, i - 1);
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	//insert_sort();
	//selection_sort();
	heap_sort();
	for (int i = 1; i <= n; i++)cout << a[i] << " ";
	return 0;
}
//
//int main()
//{
//	int n; cin >> n;
//	int ret = 0;
//	unordered_map<string, int>mp;
//	while (n--)
//	{
//		string a,b; cin >>a>>b;
//		a = a.substr(0, 2);
//		if (a == b)continue;
//		ret += mp[b + a];
//		mp[a+b]++;
//	}
//	cout << ret << endl;
//}
////
////typedef long long ll;
////const int N = 2e5 + 10;
////ll n, c;
////ll a[N];
////unordered_map<int,int>mp;
////
////int main()
////{
////	cin >> n >> c;
////	for (int i = 1; i <= n; i++)
////	{
////		cin >> a[i];
////		mp[a[i]]++;
////	}
////	ll ret = 0;
////	for (int i = 1; i <= n; i++)
////	{
////		ret += mp[c + a[i]];
////	}
////	cout << ret << endl;
////}
////
//////int main()
//////{
//////	
//////	int N; cin >> N;
//////	while(N--)
//////	{
//////		int L; cin >> L;
//////		for (int i = 1; i <= L; i++)
//////		{
//////			string s; cin >> s;
//////			mp[s].insert(N);
//////		}
//////	}
//////
//////	int m; cin >> m;
//////	while (m--)
//////	{
//////		string s; cin >> s;
//////		for (auto i : mp[s])
//////		{
//////			cout << i << " ";
//////		}
//////		cout << endl;
//////	}
//////	return 0;
//////}
////////int main()
////////{
////////	int T;// cin >> T;
////////	scanf("%d", &T);
////////	while (T--)
////////	{
////////		int n; //cin >> n;
////////		scanf("%d", &n);
////////		unordered_set<int> mp;
////////		for (int i = 1; i <= n;i++)
////////		{
////////			int x;// cin >> x;
////////			scanf("%d", &x);
////////			if (!mp.count(x))
////////			{
////////				printf("%d ", x);//cout << x << " ";
////////				mp.insert(x);
////////			}
////////		}
////////		printf("\n");//cout << endl;
////////	}
////////	return 0;
////////}
//////////
//////////int main()
//////////{
//////////	unordered_map<string, int>mp;
//////////	int T; cin >> T;
//////////
//////////	while (T--)
//////////	{
//////////		int op; cin >> op;
//////////		string name; 
//////////		if (op == 1)
//////////		{
//////////			cin >> name;
//////////			int x; cin >> x;
//////////			mp[name] = x;
//////////			cout << "OK" << endl;
//////////		}
//////////		else if (op == 2)
//////////		{
//////////			cin >> name;
//////////			if (mp.count(name))cout << mp[name] << endl;
//////////			else cout << "Not found" << endl;
//////////		}
//////////		else if (op == 3)
//////////		{
//////////			cin >> name;
//////////			if (mp.count(name))
//////////			{
//////////				mp.erase(name);
//////////				cout << "Deleted successfully" << endl;
//////////			}
//////////			else cout << "Not found" << endl;
//////////		}
//////////		else
//////////		{
//////////			cout << mp.size() << endl;
//////////		}
//////////	}
//////////	return 0;
//////////}